//index.js
//获取应用实例

//引入 发送网络请求的方法
const http = require('../../utils/http.js');
import regeneratorRuntime from '../../lib/runtime/runtime'
Page({
  data: {
   
    imgUrls: [],
   
    indicatorDots: false,
    autoplay: true,
    interval: 3000,
    duration: 1000,
    bannerHeight: 421.5,// Math.ceil(290.0 / 750.0 * getApp().screenWidth),
    jianjie_txt: ''
  
  },
  //事件处理函数
 
  onLoad: function (options) {
    
   
   
    this.loadnews()
   
  },
  //转义方法
  escape2Html(str) {
    var arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"' };
    return str.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) { return arrEntities[t]; }).replace('<section', '<div').replace('<img', '<img style="max-width:100%;height:auto" ');
  },

  async loadnews() {
    //从后台读取首页信息
    let url = 'topnews/index'
    let data = {
      id: 1     
    }
    let res= await http.post(url,data)
   
    let imgUrls=new Array()
    imgUrls[0]=res.imgUrls1
    imgUrls[1]=res.imgUrls2
    imgUrls[2]=res.imgUrls3
    this.setData({
      imgUrls: imgUrls,       
      jianjie_txt: this.escape2Html(res.jianjieTxt)
     })
  },//end of loadnews
  
})
